﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartVoice
{
    class GPS
    {
        public double ConvertToRad(double x)
        {
            return (Math.PI / 180) * x;
        }

        public double DistanceBetweenTwoPoints(double lat1, double lon1, double lat2, double lon2)
        {
            double R = 6371; // km            
            double dLat = ConvertToRad(lat2 - lat1);
            double dLon = ConvertToRad(lon2 - lon1);

            double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
                    Math.Cos(ConvertToRad(lat1)) * Math.Cos(ConvertToRad(lat2)) *
                    Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
            double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
            double d = R * c;
            return d;
        }
    }
}
